


var isdata=0;
var typedata;
var pagindex=0;
var pagesize=10;
var itemIndex = 0;
var tabLoadEndArray = [false, false, false];
var tabScroolTopArray = [0, 0, 0];
var  ordeid=getUrlParam('ordeid');
mui('body').on('tap','a',function(){document.location.href=this.href;});

function createFragment(me,itemIndex,username) {
    // 等级类型:0=粉丝,1=客户,2=一级经纪人,3=代理商,4=后续经纪人
    var data;
    if (itemIndex==0)
    {
        data= {
            level:"",
            username:username,
            pageindex:pagindex,
            pagesize:pagesize
    }
    }
    if (itemIndex==1)
    {
        data= {
            level:2,
            username:username,
            pageindex:pagindex,
            pagesize:pagesize
        }
    }
    if (itemIndex==2)
    {
        data= {
            level:3,
            username:username,
            pageindex:pagindex,
            pagesize:pagesize
        }
    }
    if (itemIndex==3)
    {
        data= {
            level:4,
            username:username,
            pageindex:pagindex,
            pagesize:pagesize
        }
    }
    var result = '';
    mui.post('/User/adminfinduser', data, function (info) {
        console.log(info);
        var datas = info.object;

        if(datas.length === 0){
            me.lock();
            me.noData();
            me.resetload();
            return;
        }else {
            for (var i = 0; i < datas.length; i++) {
                cold = datas[i];
                result
                    += ''
                    + '    <hgroup class="khfxRow">'
                    + '      <header>注册时间：'+formattimeuser(cold['createtime'])+'</header>'
                    + '      <div class="mid">'
                    + '        <img class="photo" src="'+cold['avatar']+'" >'
                    + '        <span><label>姓名：</label>'+cold['username']+'</span> '
                    + '        <span><label>余额：</label>'+cold['money']+'</span> '
                    + '        <span><label>电话：</label>'+cold["mobile"]+'</span> '
                    + '        <span><label>地址：</label>'+cold['address']+'</span> '
                    + '        <span><label>局部物料：</label>'+cold['materielA']+'</span> '
                    + '        <span><label>全套物料：</label>'+cold['materielB']+'</span> '
                    + '      </div>'
                    + '      <footer style="height: 40px;">'+adminuserbtn(ordeid,cold['id'],cold['username'])+'</footer>'
                    + '    </hgroup>';
            }
            $('.khfxPane').eq(itemIndex).append(result);

            if(datas.length %10!=0){
                me.$domDown.html(me.opts.domDown.domNoData);
            }
            else {
                me.resetload();
                me.$domDown.html(me.opts.domDown.domRefresh);
            }
            pagindex=pagindex+10;
        }

    });

};

function saveordeuser(ordeid,userid,username){
    mui.post('/Order/updatefreeOrderassitant',
        {
            id:ordeid,
            assitant:username,
            assitantid:userid
        },
        function(data){
            console.log(data);
            if (data.code){
                window.history.back();location.reload();
                mui.toast('指派成功！');
            }
        },'json'
    )
}



$(function () {
    var itemIndex = 0;
    var tabLoadEndArray = [false, false, false];
    var tabScroolTopArray = [0, 0, 0];
    // dropload
    var dropload = $('.khfxWarp').dropload({
        scrollArea: window,
        domDown: {
            domClass: 'dropload-down',
            domRefresh: '<div class="dropload-refresh">上拉加载更多</div>',
            domLoad: '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
            domNoData: '<div class="dropload-noData">已无数据</div>'
        },
        loadDownFn: function (me) {
            setTimeout(function () {
                createFragment(me, itemIndex,"");
            }, 500);
        }
    });
    $('#searchForm button').on('click', function () {
            username = document.getElementById('searchInput').value;
            if (username==""||username==undefined||username==null) {
                username="";
            }

                $('.khfxPane hgroup').remove();
                pagindex=0;
                pagesize=10;
                createFragment(dropload, itemIndex, username);

    });

    $('.tabHead span').on('click', function () {

        tabScroolTopArray[itemIndex] = $(window).scrollTop();
        var $this = $(this);
        itemIndex = $this.index();
        $(window).scrollTop(tabScroolTopArray[itemIndex]);

        pagindex=0;
        pagesize=10;

        $('.khfxPane hgroup').remove();
        $(this).addClass('active').siblings('.tabHead span').removeClass('active');
        $('.tabHead .border').css('left', $(this).offset().left + 'px');
        $('.khfxPane').eq(itemIndex).show().siblings('.khfxPane').hide();

        if (!tabLoadEndArray[itemIndex]) {
            dropload.unlock();
            dropload.noData(false);
        } else {
            dropload.lock('down');
            dropload.noData();
        }
        dropload.resetload();
    });
});